package net.mikoo.seals.agent.biz.services.impl;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.mikoo.seals.agent.biz.mapper.client.CompanyMapper;
import net.mikoo.seals.agent.biz.services.CompanyServices;
import net.mikoo.seals.agent.common.BaseServices;
import net.mikoo.seals.agent.common.PageModel;
import net.mikoo.seals.agent.common.enums.CompanyStatusEnum;
import net.mikoo.seals.agent.common.exception.ParametersException;
import net.mikoo.seals.agent.model.Company;
import net.mikoo.seals.agent.model.CompanyQuery;

@Service
public class CompanyServicesImpl extends BaseServices implements CompanyServices {
	
	Logger logger = LoggerFactory.getLogger(CompanyServicesImpl.class);

	@Autowired
	private CompanyMapper companyMapper;
	
	@Override
	public void save(Company company) {
		
		if(company == null){
			throw new ParametersException("company is null!");
		}
		
		company.setCompanyStatus(CompanyStatusEnum.CREATED.code());
		company.setCreateTime(new Date());
		
		companyMapper.insert(company);
	}

	@Override
	public void modifyByPrimaryKey(Company company) {
		
		if(company == null){
			throw new ParametersException("company is null!");
		}
		companyMapper.delete(company);
	}
	
	@Override
	public Company loadByPrimaryKey(Long companyId) {
		
		if(companyId == null){
			throw new ParametersException("companyId is null!");
		}
		
		Company company = companyMapper.selectInfoById(companyId);
		return company;
	}
	
	
	@Override
	public void deleteByPrimaryKey(Long companyId) {
		
				
	}
	
	@Override
	public PageModel<Company> loadByQueryToPage(CompanyQuery query) {
		
		
		List<Company> datas = companyMapper.selectByQueryToPage(query);
		Integer total = companyMapper.countByQueryToPage(query);
		PageModel<Company> pm = new PageModel<Company>(total,datas);
		return pm;
	}

	@Override
	public List<Company> getListByQuery(CompanyQuery query) {
		
		List<Company> companys  = companyMapper.selectListByQuery(query);
		
		return companys;
		
	}

	
}
